import { DataTypes } from 'sequelize';
import { Migration } from '../umzug';

export const up: Migration = async ({ context: sequelize }) => {
  const {
    INTEGER, DATE, STRING, DOUBLE
  } = DataTypes;
  await sequelize.getQueryInterface().createTable(
    'merge_user_questionnaire',
    {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      uuid: { type: STRING(36), unique: true },
      fk_user: {
        type: INTEGER,
        references: {
          model: {
            tableName: 'users',
          },
          key: 'id',
        },
      },
      fk_questionnaire: {
        type: INTEGER,
        references: {
          model: {
            tableName: 'questionnaires',
          },
          key: 'id',
        },
      },
      email: { type: STRING },
      start_time: { type: DOUBLE },
      end_time: { type: DOUBLE },
      complate_flag: { type: INTEGER },
      created_at: { type: DATE },
      updated_at: { type: DATE },
    }
  );
};

export const down: Migration = async ({ context: sequelize }) => {
  await sequelize.getQueryInterface().dropTable('merge_user_questionnaire');
};
